﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UI.Data;

namespace UI.Controllers
{
    public class UserController : Controller
    {
        private readonly SPORTSALEEntities context = new SPORTSALEEntities();
        //
        // GET: /User/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /User/Details/5

        public ActionResult Details(/*int id*/)
        {
            return View();
        }

        //
        // POST: /User/Edit/5
        public ActionResult List(/*int id*/)
        {
            return View(context.Usuarios);
        }

        public ActionResult Alta(int id)
        {
            Usuarios u = context.Usuarios.Where(x => x.Id == id).First();
            u.Activo = 1;

            try
            {
                context.BlackList.DeleteObject(context.BlackList.Where(x => x.IdUsuario == id).First());
            }
            catch (Exception)
            {
            }

            context.SaveChanges();

            return View("List", context.Usuarios);
        }

        public ActionResult Baja(int id)
        {
            Usuarios u = context.Usuarios.Where(x => x.Id == id).First();
            u.Activo = 0;

            context.BlackList.AddObject(new BlackList() { IdUsuario = u.Id, Razon = "Dado de baja por el administrador", Vencimiento = DateTime.MaxValue });

            context.SaveChanges();

            return View("List", context.Usuarios);
        }
    }
}
